import useSeatStore from "@/store/seat.js";
import graphicData from "./graphicData.json";

const seatStore = useSeatStore();
const groupsCount = 3;
export default function () {
  let seatData = seatStore.seatStatus.filter(
    (cell) =>
      cell.orgID == 4 &&
      cell.sectorYes == 1 &&
      cell.sectorCodes &&
      cell.sectorCodes.length > 0
  );
  let result = new Array();
  for (let i = 0; i < seatData.length; i++) {
    //
    let seat = seatData[i];
    let seatName = seat.seatName;
    let frequency =
      seatStore.valueTarget == "planning"
        ? seat.planningFrequency
        : seat.frequency;
    let sectorCodes =
      seatStore.valueTarget == "planning"
        ? seat.planningSectorCodes ?? []
        : seat.sectorCodes;
    for (let j = 0; j < groupsCount; j++) {
      let pointsLists = graphicData.polygons.filter(
        (polygon) => sectorCodes.includes(polygon.id) && polygon.group == j
      );
      if (pointsLists.length) {
        let x = 0;
        let y = 0;
        let counts = 0;
        for (let k = 0; k < pointsLists.length; k++) {
          let points = pointsLists[k].points.split(" ");
          if (points.length) {
            for (let l = 0; l < points.length; l += 2) {
              counts++;
              x += Number(points[l]);
              y += Number(points[l + 1]);
            }
          }
        }
        if (counts) {
          // console.log("getLabels", seatName, x, y, counts);
          x = x / counts;
          y = y / counts;
          result.push({
            x,
            y,
            id: seatName,
            seatName,
            sectorCodes,
            frequency,
          });
        }
      }
    }
  }
  return result;
}

/*
borderOn:0
color:"#666666"
defaultColor:"#F4A460"
frequency:125.7
logicSectorCode:"OP10"
orgGroup:"ACC"
orgID:4
orgName:"区域管制三室"
planningFrequency:null
planningSectorCodes:null
seatName:"ACC10"
seatPostList:Array[3]
seatType:"普通管制"
sectorCodes:Array[1]
sectorYes:1
*/
